import http from "@/utils/http";

/**
 * User
 */
export interface User {
    createTime?: Date;
    id?: number;
    lastLoginTime?: Date;
    password?: string;
    role?: string;
    sellerRoleList?: string[],
    updateTime?: Date;
    username?: string;
}

export function login(username: string, password: string) {
    return http.post('/sys/login', {
        username,
        password
    })
}

export function isLogin() {
    return http.get('/sys/isLogin')
}

export function getCurrentUser() {
    return http.get('/sys/getCurrentUser')
}

export function logout() {
    return http.post('/sys/logout')
}

export function register(username: string, password: string) {
    return http.post('/sys/register', {
        username,
        password
    })
}

export function changePassword(dto: any) {
    return http.post('/sys/changePassword', dto)
}

export function activeAccount(password: string) {
    return http.post('/sys/activeAccount', {
        password
    })
}

export function list() {
    return http.post<User[]>('/sys/list')
}

export function update(user: User) {
    return http.post('/sys/update', user)
}

export function addUser(user: User) {
    return http.post('/sys/addUser', user)
}

export function resetPassword(id: number) {
    return http.post(`/sys/resetPassword?id=${id}`)
}

export function removeUser(id: number) {
    return http.post(`/sys/deleteUser?id=${id}`)
}

export function getLogs() {
    return http.get<string>(`/sys/getLog`)
}